'use strict'
const config = require('../config');
const mysql = require('mysql');
const pool = mysql.createPool({
  ...config,
});

module.exports.up = function (next) {
  pool.query("show databases", (err, databases) => {
    if (err) throw err.message;
    if (databases.some(db => db.Database === 'eitailfox')) return next();

    pool.query("CREATE DATABASE  `eitailfox` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", err => {
      if (err) throw err.message;
      next()
    });
  });
}
